package logic

import (
	"context"
	"store/model/mysql"

	"store/userrpc/internal/svc"
	"store/userrpc/userrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateLogic {
	return &UpdateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UpdateLogic) Update(in *userrpc.UpdateRequest) (*userrpc.UpdateResponse, error) {
	// todo: add your logic here and delete this line

	var store mysql.Store
	mysql.DB.Debug().Where("id=?", in.Id).Find(&store)

	store.Name = in.Name
	store.Addr = in.Addr
	store.Tel = in.Tel
	mysql.DB.Debug().Updates(&store)
	return &userrpc.UpdateResponse{Id: int64(store.ID)}, nil
}
